<template>
  <div>
    <el-table :data="tableData" stripe style="width: 100%" showSummary :summaryMethod="getTotal">

      <el-table-column type="index" label="序号" width="50"></el-table-column>
      <el-table-column prop="hash.username" label="员工姓名" width="80"></el-table-column>
      <el-table-column prop="hash.sqdeptname" label="员工部门" width="300"></el-table-column>
      <el-table-column prop="hash.examinetime" label="报销时间" width="150"></el-table-column>
      <el-table-column prop="hash.mounttypename" label="报销种类" width="150"></el-table-column>
      <el-table-column prop="hash.childmounttypename" label="报销子类" width="150">
        <template slot-scope="scope">
          <div @click="opendiag(scope.row)" style="color:#26a2ff;cursor:pointer">
            {{scope.row.hash.childmounttypename}}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="hash.amount" label="单项金额" width="150"></el-table-column>
      <el-table-column prop="hash.deptname" label="报销部门" width="200"></el-table-column>
      <el-table-column prop="hash.content" label="报销内容" width="150"></el-table-column>

      <el-table-column prop="hash.paytypename" label="支付方式" width="150"></el-table-column>
      <el-table-column prop="hash.amountsum" label="总金额" width="150"></el-table-column>
      <el-table-column prop="hash.beizhu" label="备注" width="150"></el-table-column>

    </el-table>
    <el-pagination @current-change="handleCurrentChange" :currentPage.sync="pagobj.currentPage3" :pageSize="pagobj.pagesize" layout="total, prev, pager, next" :total="pagobj.total" style="margin:20px 0;text-align:center"></el-pagination>

  </div>
</template>

<script>
export default {
  data () {
    return {
      dialogImageUrl: '',
      dialogVisible2: false,
      dialogVisible: false,
      ts: this.newStore(),
    };
  },
  props: {
    tableData: {
      type: Array,
      required: true,
    },
    pagobj: {
      type: Object,
      required: true,
    },
  },
  methods: {
    handleCurrentChange () {
      this.$parent.getlist();
    },
    opendiag (item) {
      this.$parent.opendiag(item);
    },
    getTotal (param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计';
          return;
        }
        console.log(column.property);

        if (column.property == 'hash.amount') {
          const values = data.map(item => Number(item.hash.amount));

          console.log(data);
          console.log(values);

          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            }
            return prev;
          }, 0);
        } else {
          sums[index] = '--';
        }
      });

      return sums;
    },
  },
};
</script>

<style>
.cell {
  text-align: center;
}
</style>
